﻿using System.CommandLine;
using SqlSharp.Infrastructure;

Option<FileInfo> configOption = new("--config-file", "-c")
{
    Description = "Path to the configuration file.",
    Required = false
};

Option<bool?> forceOption = new("--force", "-f")
{
    Description = "Force override existing files without prompting.",
    Required = false
};

Option<string> outputOption = new("--output-path", "-o")
{
    Description = "Path to the output directory for generated files.",
    Required = true
};

Option<FileInfo> templateOption = new("--template-file", "-t")
{
    Description = "Path to the template file.",
    Required = true
};

RootCommand rootCommand = new("Entity class generation utility for database modeling.");
rootCommand.Options.Add(configOption);
rootCommand.Options.Add(outputOption);
rootCommand.Options.Add(forceOption);
rootCommand.Options.Add(templateOption);
rootCommand.SetAction(parseResult =>
{
    try
    {
        var configPath = parseResult.GetValue(configOption) ?? new FileInfo("./config");
        var outputPath = parseResult.GetValue(outputOption) ?? "./";
        var templatePath = parseResult.GetValue(templateOption) ?? new FileInfo("./template.cj");
        var force = parseResult.GetValue(forceOption) ?? false;
        TemplateUtility.Render(configPath, outputPath, templatePath, force);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        return -1;
    }

    return 0;
});
var parseResult = rootCommand.Parse(args);
parseResult.Invoke();